package com.walker.nacos.demo.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @ProjectName: walker-step
 * @Package: com.walker.nacos.demo.controller
 * @ClassName: ConfigController
 * @Author: yangyl
 * @CreateDate: 2021/9/28 18:10
 */
@RestController
@RequestMapping("/config")
public class ConfigController {

    @NacosValue(value = "${name}",autoRefreshed = true)
    private String name;
//    @NacosValue("${age}")
//    private Integer age;
//    @NacosValue("${backup}")
//    private boolean backup;

    @NacosValue(value = "${open.url}",autoRefreshed = true)
    private String openUrl;
    @NacosValue(value = "${open.port}",autoRefreshed = true)
    private Integer port;

    @GetMapping("/test1")
    public Map<String,Object> getTest(){
        Map<String,Object> data=new HashMap<>();
        data.put("name",name);
//        data.put("age",age);
//        data.put("backup",backup);
        return data;
    }

    @GetMapping("/openConfig")
    public Map<String,Object> getOpenConfig(){
        Map<String,Object> data=new HashMap<>();
        data.put("openUrl",openUrl);
        data.put("openPort",port);
        return data;
    }
}
